package com.ghost.alibabaghost.result;

import java.util.List;

/**
 * @author yaolisheng
 * @version 1.0
 * @date 2022/1/10 10:29 PM
 */
public class QueryPageInfo <T>{

    private Integer pageNum;
    private Integer pageSize;
    private Integer total;
    private String data;
    private List<T> list;

    public Integer getPageNum() {
        return pageNum;
    }

    public void setPageNum(Integer pageNum) {
        this.pageNum = pageNum;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotal() {
        return total;
    }

    public void setTotal(Integer total) {
        this.total = total;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public void pageHelper(List<T> list){
        this.total = list.size();
        int fromIndex = pageNum == 1 ? 0 : pageNum * pageSize - pageSize;
        int toIndex = this.total < pageNum * pageSize ? this.total : pageNum * pageSize;
        this.list = list.subList(fromIndex,toIndex);
    }

    @Override
    public String toString() {
        return "QueryPageInfo{" +
                "pageNum=" + pageNum +
                ", pageSize=" + pageSize +
                ", total=" + total +
                ", data='" + data + '\'' +
                ", list=" + list +
                '}';
    }
}
